﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Enter.Common
{
    /// <summary>
    /// 通用返回类
    /// </summary>
    [Serializable]
    public partial class ResultPacket
    {
        /// <summary>
        /// 版本信息
        /// </summary>
        private const string VERSION = "1.0";
        private bool _IsError;
        private string _ResultCode;
        private string _Description;
        /// <summary>
        /// 构造函数
        /// </summary>
        public ResultPacket()
        {
            _IsError = false;
            _ResultCode = "00";
            _Description = "操作成功";
        }
        /// <summary>
        /// 构造函数 
        /// </summary>
        /// <param name="pIsError"></param>
        public ResultPacket(bool pIsError)
        {
            _IsError = pIsError;
            _ResultCode = "99";
            _Description = "操作失败";
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="pDescription"></param>
        public ResultPacket(string pDescription)
        {
            _IsError = true;
            _ResultCode = "99";
            _Description = pDescription;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="pResultCode"></param>
        /// <param name="pDescription"></param>
        public ResultPacket(int pResultCode, string pDescription, params object[] arg)
        {
            _IsError = pResultCode != 0;
            _ResultCode = pResultCode.ToString("#00");
            _Description = string.Format(pDescription, arg);
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="pIsError"></param>
        /// <param name="pResultCode"></param>
        /// <param name="pDescription"></param>
        public ResultPacket(bool pIsError, string pResultCode, string pDescription, params object[] arg)
        {
            _IsError = pIsError;
            _ResultCode = pResultCode;
            _Description = string.Format(pDescription, arg);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return string.Format("Ver={0}&Result={1}&Msg={2}", VERSION, this._ResultCode, this._Description);
        }
        /// <summary>
        /// 返回是否错误,false：没有错误 true：有错误
        /// </summary>
        public bool IsError
        {
            get
            {
                return _IsError;
            }
            set
            {
                _IsError = value;
            }
        }

        /// <summary>
        /// 返回错误文本代码
        /// </summary>
        public string ResultCode
        {
            get
            {
                return _ResultCode;
            }
            set
            {
                _ResultCode = value;
            }
        }
        /// <summary>
        /// 返回错误文本信息
        /// </summary>
        public string Description
        {
            get
            {
                return _Description;
            }
            set
            {
                _Description = value;
            }
        }
    }
}
